*Decentralization causes May 2023*
*DO FILE TO CREATE MARGINAL EFFECTS GRAPHs*
*Fig 1 where g vulnerability modifies ethnoterritorial party threat*

#delimit ;

mixed raiapproved ethnicthreat_lg gvuln_lg gvuln_lgXethreat_lg raiapproved_lg || countryno: || regionno:;

#delimit ;


 
*     ****************************************************************  *;
*              railevel  i.e. x2 = MV                               *;
*     ****************************************************************  *;
generate MV=((_n-1)/10);    

replace MV=. if _n>4000;

matrix b=e(b);
matrix list e(b);
matrix V=e(V);
matrix list e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];


scalar list b1 b2 b3 varb1 varb3 covb1b3;

gen conb=b1+b3*gvuln_lg if _n<4000;



*     ****************************************************************  *;
*      These create conditional coefficients for b1 at MV       *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*gvuln_lg^2+2*covb1b3*gvuln_lg)  if _n<4000;
set more off;
gen cont= conb/conse;


*     ****************************************************************  *;
*      This creates a conditional t                                               *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Generate confidence intervals at the 95% level                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=1.96*conse;
gen upper=conb+a;
gen lower=conb-a;
set textsize 100;


label variable conb "Marginal Effect of Ethnoterritorial Threat";
label variable upper "95% CI - upper bound";
label variable lower "95% CI - lower bound";
label variable  gvuln_lg "Governmental Vulnerability";



*     ****************************************************************  *;
*       Graph the effect of e threat on rai conditional on gvuln_lg   *;
*                                          *;
*     ****************************************************************  *;
*this gives the full range*;



#delimit ;
gen where=-.359;
gen pipe = "|";
egen tag_gvuln=tag(gvuln_lg) if M45obs==1;

#delimit ;

sort gvuln_lg;

twoway (line conb gvuln_lg, clpat(solid)) (line upper gvuln_lg, clpat(shortdash) lcolor(gs8)) (line lower gvuln_lg, clpat(shortdash) lcolor(gs8)), yline(0) ytitle("Conditional Coefficient of Ethnoterritorial Threat") legend(off), scatter where gvuln_lg if tag_gvuln, plotr(m(b4)) ms(none) mlabcolor(gs5) mlabel (pipe) mlabpos(6);
